<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\ocean;

use app\model\OeSourceUrlModel;
use app\service\BaseService;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class SourceUrlService extends BaseService
{
    /**
     * 获取信息.
     * @return null|array|mixed|OeSourceUrlModel|\think\Model
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public static function getInfo(array $params = [])
    {
        $where = [];
        if (! empty($params['id'])) {
            $where[] = ['id', '=', intval($params['id'])];
        }

        return (new OeSourceUrlModel())->where($where)->field(true)->find();
    }

    /**
     * 获取列表.
     *
     * @return array|Collection|OeSourceUrlModel[]
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public static function getList(array $params = [])
    {
        $where = [];
        if (! empty($params['ids'])) {
            $where[] = ['id', 'in', explode(',', $params['ids'])];
        }

        return (new OeSourceUrlModel())->where($where)->field(true)->select();
    }
}
